
#pragma once 
#include <QString>
#include <QTimer>

#include "../deskcore/core/core.h"
#include "../deskcore/keyevent/InputInjector.h"
#include "../deskcore/keyevent/KeyMap.h"
#ifdef _WIN32
#include <exdisp.h>
#include <comdef.h>
#endif
class Friend;
class CSessionFrameWnd;

class ToxMainWnd :public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString myid READ myId WRITE setMyId NOTIFY myIdChanged)
    Q_PROPERTY(int fid READ fid WRITE setFid)
    Q_PROPERTY(int avstatus  READ avStatus WRITE setAvStatus NOTIFY avStatusChanged)
    Q_PROPERTY(int constatus READ conStatus WRITE setConStatus NOTIFY conStatusChanged)

public:
    ToxMainWnd(QObject *parent = nullptr);

    QString myId()const;
    void setMyId(const QString &id);

    int fid()const;
    void setFid(const int fid);

    int conStatus() const;
    void setConStatus(int status);
    int avStatus() const;
    void setAvStatus(int status);

    Q_INVOKABLE void startCon(const QString& toId);
    Q_INVOKABLE void stopCon();
    void init();

signals:
    //Signal must begin by a lowercase letter in your C++ code, i.e void yourLongSignal()
    //Signal handler in QML will be named on<YourLongSignal>
    void myIdChanged();
    void avStatusChanged();
    void conStatusChanged();


protected:
    void timerEvent(QTimerEvent *event);
private:
	void onCoreChanged(Core& core);

	void onConnected();
	void onDisconnected();
	void addFriend(uint32_t friendId, const ToxPk& friendPk);
	void onFriendRequestReceived(const ToxPk& friendPk, const std::string& message);
	void onFriendDataReceived(uint32_t friendnumber, const ToxString& message, bool isAction);

	void onAvInvite(uint32_t friendId, bool video);
	void onAvStart(uint32_t friendId, bool video);
	void onAvEnd(uint32_t friendId, bool error);

	void conTimerProc();
    void setMouseEvent(int x, int y,  unsigned char keyFlag);
    void setKeyboardEvent(uint32_t keySym, bool down);
private:
    Friend* f;
    int fId;
    bool bConnecting = false;
    unsigned char m_prevKeyFlag;
    int connectCount = 0;
    //QTimer *conTimer;
    QString remoteId_;
    QString myId_;
    int conStatus_;
    int avStatus_;
    int conTimerId;
#ifdef _WIN32
    KeyMap m_keyMap;
    InputInjector m_inputInjector;
#endif
    //...
};



//Q_DECLARE_METATYPE(ToxMainWnd)
